import { defineStore } from 'pinia'
import { ref } from 'vue'
import { reqCategory1, reqCategory2, reqCategory3 } from '@/api/product/attr/index'
import type { categoryDataArr } from '@/api/product/attr/type'
const useCategoryStore = defineStore('Category', () => {
  const category1 = ref<categoryDataArr>([])
  const category1Id = ref('')
  const category2List = ref<categoryDataArr>([])
  const category2Id = ref('')
  const category3List = ref<categoryDataArr>([])
  const category3Id = ref('')
  const getCategory1 = async () => {
    const res = await reqCategory1()
    if (res.code == 200) {
      category1.value = res.data
    }
  }
  const getCategory2 = async () => {
    const res = await reqCategory2(category1Id.value)
    if (res.code == 200) {
      category2List.value = res.data
    }
  }
  const getCategory3 = async () => {
    const res = await reqCategory3(category2Id.value)
    if (res.code == 200) {
      category3List.value = res.data
    }
  }
  return {
    category1,
    category1Id,
    getCategory1,
    getCategory2,
    category2List,
    category2Id,
    getCategory3,
    category3List,
    category3Id
  }
})
export default useCategoryStore
